package com.wenx.remotestrategy;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Random;

public class RemoteService implements RemoteInterface {

    private static final Random random = new Random();

    @Override
    public Object getRemoteResult(String id) {
        //模拟远程访问的延迟，延迟2-2.5秒
        int delay = random.nextInt(2000) + 500;

        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return id + " "+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-DD HH:mm:ss"));
    }

    @Override
    public List<String> getResults(List<String> ids) {
        //模拟远程访问的延迟，延迟2-2.5秒
        int delay = random.nextInt(2000) + 500;

        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return ids;
    }


    public static void main(String[] args) {
        Random random = new Random();
        System.out.println(random.nextLong());
        System.out.println(random.nextInt());
        System.out.println(random.nextInt(10));
    }

}
